package com.fht.controller.set;


import com.fht.entity.MerchantsInformation;
import com.fht.entity.SetPay;
import com.fht.service.food.MerchantsInformationService;
import com.fht.util.ResultVOUtil;
import com.fht.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@Slf4j
@RequestMapping("/merchants/information")
public class MerchantsInformationController {


    @Autowired
    public MerchantsInformationService merchantsInformationService;

    //菜品类别展示
    @GetMapping("/index")
    public String index(Model model){

        //TODO 登录用户所在店铺ID
        MerchantsInformation merchantsInformation = merchantsInformationService.selectById("2019001");
        List<MerchantsInformation> merchantsInformationList = merchantsInformationService.findAllIdAndName();
        model.addAttribute("merchantsInformationList",merchantsInformationList);

        model.addAttribute("merchantsInformation",merchantsInformation);

        return "set/merchantsInformation/index";

    }

    //修改map缓存中的数据，并重新计算价格总和
    @PostMapping("/edit")
    @ResponseBody
    public ResultVO edit (MerchantsInformation merchantsInformation){

        merchantsInformationService.update(merchantsInformation);

        return ResultVOUtil.ok();
    }

}
